package com.nbsaas.boot.example.rest.convert;

import com.nbsaas.boot.example.data.entity.ExampleCatalog;
import com.nbsaas.boot.example.api.domain.response.ExampleCatalogResponse;

import com.nbsaas.boot.utils.BeanDataUtils;
import com.nbsaas.boot.rest.api.Converter;
import java.util.HashMap;
import java.util.Map;
/**
* 案例分类-实体对象转化成响应对象
*/

public class ExampleCatalogResponseConvert  implements Converter<ExampleCatalogResponse,ExampleCatalog> {

    @Override
    public ExampleCatalogResponse convert(ExampleCatalog source) {
        ExampleCatalogResponse  result = new  ExampleCatalogResponse();
        BeanDataUtils.copyProperties(source, result);
                    if(source.getParent()!=null){
                        result.setParent(source.getParent().getId());
                    }
                    if(source.getCreator()!=null){
                        result.setCreator(source.getCreator().getId());
                    }

                    try {
                        if(source.getCreator()!=null){
                            result.setCreatorName(source.getCreator().getName());
                        }
                    } catch (Exception ignored) { }


                    try {
                        if(source.getParent()!=null){
                            result.setParentName(source.getParent().getName());
                        }
                    } catch (Exception ignored) { }

                    if(source.getShowHome()!=null){
                    Map<Integer,String> ShowHomeMap=new HashMap<>();
                        ShowHomeMap.put(2,"否");
                        ShowHomeMap.put(1,"是");
                    String label=  ShowHomeMap.get(source.getShowHome());
                    result.setShowHomeName(label);
                    }
                    result.setShowHome(source.getShowHome());
        return result;
    }

}

